<?php

class MAISlideshow extends FTAObject {
		
		var $cmsDocument;
		var $gallery;
		var $galleryImages;	
		
		function MAISlideshow(){
			parent::__construct();
				
			global $db;	
			$this->cmsDocument = new CmsDocument($db);
		}
		
		function getGallery($galleryDocumentCode){
			$this->cmsDocument->flush();
			$this->cmsDocument->setActiveDocuments();
			$this->cmsDocument->addDocumentType('docFileMod');
			$this->cmsDocument->addConstraint("documentcode", $galleryDocumentCode);
			$this->cmsDocument->addConstraint("author", 1);
			$this->cmsDocument->setPageSize(1);
			$this->cmsDocument->resetIterator();
			
			$this->gallery = null;
			if($this->cmsDocument->totalDocuments() > 0){
				$this->gallery = $this->cmsDocument->openCurrentDocumentFromCache();
			} 			
		}
		
		function getHomeGalleryImages(){
			$this->galleryImages = null;
			
			$this->cmsDocument->flush();
			$this->cmsDocument->setActiveDocuments();
			$this->cmsDocument->addDocumentType('docFileMod');
			$this->cmsDocument->addConstraint("categorycode", $this->gallery->documentcode);
			$this->cmsDocument->addConstraint("author", 0);
			$this->cmsDocument->addSort("<<rank>>");
			$this->cmsDocument->setPageSize(null);
			$this->cmsDocument->resetIterator();
			
			if($this->cmsDocument->totalDocuments() > 0){
				$this->galleryImages = $this->cmsDocument->getAllDocuments();
			} 
			
			return $this->galleryImages;
		}
		
		
		
		function renderHomeGallery($filetypecode, $width, $height){
			if(is_null($this->galleryImages))
				return;
				
					foreach($this->galleryImages as $image){
?>
	                 <img src="/html/blob.php?document=<?= $image->documentcode; ?>&elementId=11362&filetypecode=<?= $filetypecode; ?>" alt="Mairangi Arts Centre" />
<?
					}
														
		}
		
		
		
		
}


	function mai_getSlideShow($galleryDocumentCode, $filetypecode, $width, $height) {
		ob_start();
		$maiObject = mai_getSharedSlideshowObject();		
		$maiObject->getGallery($galleryDocumentCode);
		$maiObject->getHomeGalleryImages();
		$maiObject->renderHomeGallery($filetypecode, $width, $height);
		return ob_get_clean();			
	}

	function mai_getSharedSlideshowObject(){

		global $fta_;

		global $MAISlideshowClass;
		
		if(!is_null($MAISlideshowClass) && "MAISlideshow" != $MAISlideshowClass){
		} else {
			$MAISlideshowClass = "MAISlideshow";
		}
			
		if (!array_key_exists('maiSlideshow',$fta_)){
			$fta_->maiSlideshow = new  $MAISlideshowClass();
		}
		return $fta_->maiSlideshow;
	}


?>